//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ylzinfo.ms.utils;

import com.alibaba.fastjson.annotation.JSONField;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Result implements Serializable {
    private static final long serialVersionUID = 3103957257121661311L;
    private int resultCode;
    private String resultMsg;
    private Map<String, Object> resultBody;
    public static final int CODE_ERROR = 0;
    public static final int CODE_SUCCESS = 1;
    public static final int CODE_NO_RESULT = 2;
    public static final String MSG_NO_RESULT = "没有查询到数据";
    public static final int CODE_USER_NOT_LOGIN = 20;
    public static final String MSG_USER_NOT_LOGIN = "尚未登录或登录已超时，请重新登录！";
    public static final int CODE_INVALID = 21;
    public static final String MSG_INVALID = "无效操作，请稍后再试！";
    public static final int CODE_FORBIDDEN = 403;
    public static final String MSG_FORBIDDEN = "无法操作，权限不足";
    public static final String MSG_SERVER_EXCEPTION = "服务器异常，请稍候再试！";
    public static final String KEY_ROWS = "rows";
    public static final String KEY_DATA = "data";
    public static final String KEY_OFFSET = "offset";
    public static final String KEY_LIMIT = "limit";
    public static final String KEY_TOTAL_COUNT = "total";
    public static final String KEY_TOTAL_PAGE = "totalPage";

    public Result() {
    }

    public Result(int resultCode, String resultMsg) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
    }

    @JSONField(
            serialize = false
    )
    public Object getBodyAttr(String key) {
        return this.resultBody == null?null:this.resultBody.get(key);
    }

    public void setBodyAttr(String key, Object value) {
        if(this.resultBody == null) {
            this.resultBody = new HashMap();
        }

        this.resultBody.put(key, value);
    }

    public static Result successResult() {
        return new Result(1, "成功");
    }

    public static Result successResult(String msg) {
        return new Result(1, msg);
    }

    public static Result errorResult(String msg) {
        return new Result(0, msg);
    }

    public static Result invalidResult() {
        return invalidResult((String)null);
    }

    public static Result invalidResult(String msg) {
        return new Result(21, msg == null?"无效操作，请稍后再试！":msg);
    }

    public static Result noResult(String msg) {
        return new Result(2, msg == null?"没有查询到数据":msg);
    }

    public static Result timeoutResult() {
        return new Result(20, "尚未登录或登录已超时，请重新登录！");
    }

    public static Result permDeniedResult() {
        return new Result(403, "无法操作，权限不足");
    }

    public int getResultCode() {
        return this.resultCode;
    }

    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }

    public String getResultMsg() {
        return this.resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }

    public Map<String, Object> getResultBody() {
        return this.resultBody;
    }

    public void setResultBody(Map<String, Object> resultBody) {
        this.resultBody = resultBody;
    }

    @JSONField(
            serialize = false
    )
    public Integer getOffset() {
        return (Integer)this.getBodyAttr("offset");
    }

    public void setOffset(int offset) {
        this.setBodyAttr("offset", Integer.valueOf(offset));
    }

    @JSONField(
            serialize = false
    )
    public Integer getLimit() {
        return (Integer)this.getBodyAttr("limit");
    }

    public void setLimit(Integer limit) {
        this.setBodyAttr("limit", limit);
    }

    @JSONField(
            serialize = false
    )
    public Long getTotalPage() {
        return (Long)this.getBodyAttr("totalPage");
    }

    public void setTotalPage(long totalPage) {
        this.setBodyAttr("totalPage", Long.valueOf(totalPage));
    }

    @JSONField(
            serialize = false
    )
    public Long getTotalCount() {
        return (Long)this.getBodyAttr("total");
    }

    public void setTotalCount(long totalCount) {
        this.setBodyAttr("total", Long.valueOf(totalCount));
    }

    @JSONField(
            serialize = false
    )
    public List<?> getDataList() {
        return (List)this.getBodyAttr("rows");
    }

    public void setDataList(List<?> list) {
        this.setBodyAttr("rows", list);
    }

    @JSONField(
            serialize = false
    )
    public List<?> getData() {
        return (List)this.getBodyAttr("data");
    }

    public void setData(Object obj) {
        this.setBodyAttr("data", obj);
    }

    public String toString() {
        return "Result [resultCode=" + this.resultCode + ", resultMsg=" + this.resultMsg + ", resultBody=" + this.resultBody + "]";
    }
}
